﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace B121 {
    public partial class AddNewContainerForm : Form {
        public AddNewContainerForm() {
            InitializeComponent();
        }

        #region Properties
        public ContainerClass AddedContainer { get; private set; }
        #endregion

        private void cancelBtn_Click(object sender, EventArgs e) {
            this.Close();
        }

        // Containers may not have the same name!
        private void addNewItemBtn_Click(object sender, EventArgs e) {
            if (containerNameTxtBox.Text == "") {
                throw new ArgumentException("Containers needs to have a name!");
            } else {
                AddedContainer = new ContainerClass(containerNameTxtBox.Text,
                    AccessData.TryToParseInt(containerXNumBox.Value),
                    AccessData.TryToParseInt(containerYNumBox.Value),
                    AccessData.TryToParseInt(containerZNumBox.Value),
                    AccessData.TryToParseInt(containerMaxWeightNumBox.Value));
            }
        }

        private void resetFieldsBtn_Click(object sender, EventArgs e) {
            containerMaxWeightNumBox.Value = 10000;
            containerNameTxtBox.Text = "";
            containerXNumBox.Value = 50;
            containerYNumBox.Value = 100;
            containerZNumBox.Value = 50;
        }

        private void containerNameTxtBox_TextChanged(object sender, EventArgs e) {
            addNewItemBtn.Enabled = (containerNameTxtBox.Text != "" ? true : false);
        }

        private void AddNewContainerForm_Load(object sender, EventArgs e) {
            resetFieldsBtn.PerformClick();
        }
    }
}
